<?php

namespace app\user\controller\mall\goods;

use app\user\controller\mall\Base;

/**
 * 商品
 *
 * @icon fa fa-circle-o
 */
class Goods extends Base
{
    
    /**
     * Goods模型对象
     * @var \app\common\model\mall\goods\Goods
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\mall\goods\Goods;
        $this->view->assign("goodstypeList", $this->model->getGoodstypeList());
        $this->view->assign("freighttypeList", $this->model->getFreighttypeList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->assignconfig('shop_id', cookie('shop_id'));

    }

    /**
     *查看
     * @return mixed
     */
    public function index() {

        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $total = $this->model
                ->where($where)
                ->where('shop_id',cookie('shop_id'))
                ->count();

            $list = $this->model
                ->where($where)
                ->where('shop_id',cookie('shop_id'))
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

    public function selectpage()
    {
        return parent::selectpage();
    }

}
